﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ezCloud.Data;
using Microsoft.AspNet.Identity;
using System.Threading.Tasks;
using ezCloud.Api.Common;
using System.Collections.ObjectModel;

namespace ezCloud.Api.Controllers
{
    [RoutePrefix("api/Common")]
    public class CommonDataController : ezController
    {
        [Route("CountryList")]
        public List<Countries> getAllCountries()
        {
            
            return context.Countries.Select(c => c).ToList();
        }
        [Route("OnlineUsers")]
        public async Task<IHttpActionResult> getOnlineUsers()
        {

            return Ok( Common.UserUtitily.getOnlineUsers());
        }
        [Route("OnlineUsersCount")]
        public async Task<IHttpActionResult> getOnlineUsersCount()
        {

            return Ok(Common.UserUtitily.getOnlineUsers().Count);
        }
        /* [Route("UserInfoByStaff")]
         public AspNetUsers UserInfoByStaff(Staffs staff)
         {

             return context.AspNetUsers.Where(user => user.Id == staff.UserId).FirstOrDefault();
         }*/

        [Route("HotelSizeList")]
        public List<HotelSizes> getAllHotelSizes()
        {
            
            return context.HotelSizes.Select(h => h).ToList();
        }

        [Route("LanguageList")]
        public List<Languages> getAllLanguage()
        {
            
            return context.Languages.Select(l => l).ToList();
        }
        [Route("CurrencyList")]
        public List<Currencies> getAllCurrency()
        {
            return context.Currencies.Select(l => l).ToList();
        }
        [Route("DomainToId")]
        public async Task<IHttpActionResult> GetDomainToId(string subdomain)
        {
            
            var domain = context.Hotels.FirstOrDefault(hotel => hotel.EzCloudSubdomain.ToUpper() == subdomain.ToUpper());
            var hotelId = (domain == null) ? 0 : domain.HotelId;
            return Ok(hotelId);
        }

        
        [Route("DemoHotelSystemInfo")]
        public async Task<IHttpActionResult> DemoHotelSystemInfo()
        {
            ReadOnlyCollection<TimeZoneInfo> tz;
            tz = TimeZoneInfo.GetSystemTimeZones();
            var currencies = context.Currencies.Where(curr => curr.CurrencyId == curr.CurrencyId).ToList();
            return Ok(new
            {
                TimeZones = tz,
                Currencies = currencies
            });
        }
    }
}
